home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / JTools / DevTools / BLOCK2TEXT < prev    next >
Encoding:
Text File  |  1991-12-30  |  1.3 KB  |  85 lines

  1. \ BLOCK2TEXT
  2. \
  3. \ Convert a Forth style BLOCK file to a normal text file.
  4. \
  5. \ Author: Phil Burk
  6. \ Copyright 1991 Phil Burk
  7.  
  8. ANEW TASK-BLOCK2TEXT
  9.  
  10. \ hold file pointers
  11. VARIABLE B2T-INFILE
  12. VARIABLE B2T-OUTFILE
  13.  
  14. : B2T.NEXT  ( -- 0 | 1 | -1 , process next line in file )
  15.     b2t-infile @ pad 64 fread 64 =
  16.     IF
  17.         b2t-outfile @
  18.         pad 64 -trailing  \ remove trailing blanks
  19.         dup>r
  20.         fwrite
  21.         r> =
  22.         IF
  23.             EOL pad c!  \ write line terminator
  24.             b2t-outfile @
  25.             pad 1
  26.             fwrite
  27.             1 = not
  28.         ELSE
  29.             true
  30.         THEN
  31.         \ -1 if error
  32.     ELSE
  33.         1 \ done
  34.     THEN
  35. ;
  36.  
  37. : B2T.LOOP ( -- , loop through file )
  38.     BEGIN
  39.         b2t.next
  40.         dup 0<
  41.         IF
  42.             ." B2T - Error writing file!" cr
  43.         THEN
  44.     UNTIL
  45. ;
  46.  
  47. : B2T.CLOSE ( -- , close both files )
  48.     b2t-infile @ ?dup
  49.     IF fclose b2t-infile off
  50.     THEN
  51.     b2t-outfile @ ?dup
  52.     IF fclose b2t-outfile off
  53.     THEN
  54. ;
  55.  
  56. : B2T.ERROR ( -- )
  57.     ." Usage:  BLOCK2TEXT infile outfile" cr
  58.     ."   INFILE  = file of Forth blocks" cr
  59.     ."   OUTFILE = normal text file" cr
  60.     b2t.close
  61. ;
  62.  
  63. : BLOCK2TEXT ( <infile> <outfile> -- )
  64.     >newline
  65.     ." Block2Text  by Phil Burk, written in JForth" cr
  66.     fopen ?dup
  67.     IF
  68.         b2t-infile !
  69.         new fopen ?dup
  70.         IF
  71.             b2t-outfile !
  72.             b2t.loop
  73.             ." File conversion complete." cr
  74.         ELSE
  75.             ." Could not open OUTPUT file!" cr
  76.             b2t.error
  77.         THEN
  78.     ELSE
  79.         ." Could not open INPUT file!" cr
  80.         b2t.error
  81.     THEN
  82.     b2t.close
  83. ;
  84.  
  85.